package org.lemon.transport.coap.server.service.callback;

import lombok.extern.slf4j.Slf4j;
import org.eclipse.californium.core.coap.Request;
import org.eclipse.californium.core.server.resources.CoapExchange;
import org.lemon.transport.coap.client.CoapClientState;
import org.lemon.transport.coap.client.CoapObservationState;
import org.lemon.transport.context.data.device.Device;
import org.lemon.transport.context.data.device.DeviceProfile;
import org.lemon.transport.context.session.SessionMsgListener;
import org.server.transport.gen.SessionProto;
import org.server.transport.gen.TransportProto;

import java.util.Optional;
import java.util.UUID;

@Slf4j
public class AbstractSyncSessionCallback implements SessionMsgListener {

    protected final CoapClientState state;
    protected final CoapExchange exchange;
    protected final Request request;

    public AbstractSyncSessionCallback(CoapClientState state, CoapExchange exchange, Request request) {
        this.state = state;
        this.exchange = exchange;
        this.request = request;
    }

    @Override
    public void onAttributeUpdate(UUID sessionId, TransportProto.AttributeUpdateNotificationMsg attributeUpdateNotification) {

    }

    @Override
    public void onDeviceUpdate(SessionProto.SessionInfoProto sessionInfo, Device device, Optional<DeviceProfile> deviceProfileOpt) {

    }

    @Override
    public void onDeviceDeleted(Long deviceId) {

    }

    @Override
    public void onDeviceProfileUpdate(SessionProto.SessionInfoProto newSessionInfo, DeviceProfile deviceProfile) {

    }

    @Override
    public void onRemoteSessionCloseCommand(UUID sessionId, TransportProto.SessionCloseNotificationProto sessionCloseNotification) {

    }

    @Override
    public void onGetAttributesResponse(TransportProto.GetAttributeResponseMsg attributesResponse) {

    }

    @Override
    public void onToDeviceRpcRequest(UUID sessionId, TransportProto.ToDeviceRpcRequestMsg toDeviceRequest) {

    }

    @Override
    public void onToServerRpcResponse(TransportProto.ToServerRpcResponseMsg toServerResponse) {

    }

    public static boolean isConRequest(CoapObservationState state) {
        if (state != null) {
            return state.getExchange().advanced().getRequest().isConfirmable();
        } else {
            return false;
        }
    }
}
